﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace Storage
{
    public partial class ItemAcceptance : Form
    {
        public ItemAcceptance()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        public void FillComboBox(ComboBox cb,string cmd)
        {
            MySQLDriver drv = MySQLDriver.GetDriver;
            MySqlDataReader reader = drv.Read(cmd);
            while (reader.Read())
            {
                cb.Items.Add(reader.GetString(0));
            }
            //cb.SelectedIndex = 0;
            drv.CloseConnection();
        }
        private void ItemAcceptance_Load(object sender, EventArgs e)
        {
            string cmd = "SELECT name FROM producers";
            FillComboBox(producerCbx, cmd);
            producerCbx.SelectedItem = 0;
            cmd = "Select name from items where producer_id=" + producerCbx.SelectedIndex;
            FillComboBox(itemCbx, cmd);
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            itemCbx.Items.Clear();
            string cmd = "Select name from items where producer_id=" + (producerCbx.SelectedIndex+1);
            FillComboBox(itemCbx, cmd);
        }
        private void button1_Click_1(object sender, EventArgs e)
        {
            string cmd = "INSERT INTO arrived_items(weight,item_id,date) VALUES ('" + Convert.ToInt32(weightTbx.Text)+"','"+
                 1+ "','"
                + acceptDatePicker.Value.ToString("yyyy-MM-dd") + "');";
            MySQLDriver drv = MySQLDriver.GetDriver;
            drv.ExecuteCommand(cmd);
        }
    }
}
